#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>

void* consumer(void* _context)
{
        puts("In Consumer...");
        struct Context* context = (struct Context*)_context;

        printf("Receiving Data: "); 

        pthread_mutex_lock(context->mutex);
        while(context->holder != NULL)
        {
                if(!context->error)
                {
                        putc((unsigned int)context->holder, stdout);

                        pthread_cond_signal(context->cond);
                        pthread_cond_wait(context->cond, context->mutex);
                }
                else
                {
                        pthread_cond_signal(context->cond);
                        pthread_mutex_unlock(context->mutex);

                        return NULL;
                }
        }

        pthread_cond_signal(context->cond);
        pthread_mutex_unlock(context->mutex);

        return NULL;
}